<template>
  <el-dialog
    :title="iconDialogTitle"
    :visible.sync="iconDialogIsShow"
    :close-on-click-modal="false"
    width="60%"
    heig
  >
    <div class="icons-container">
      <div class="grid">
        <div
          v-for="item of elementIcons"
          :key="item"
          @click="handleClipboard(generateElementIconCode(item),$event)"
        >
          <el-tooltip placement="top">
            <div slot="content">
              <i :class="'el-icon-' + item" />
            </div>
            <div class="icon-item">
              <i :class="'el-icon-' + item" />
              <span>{{ item }}</span>
            </div>
          </el-tooltip>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import elementIcons from './element-icons'
export default {
  name: 'IconSelect',
  props: {
    iconDialogTitle: {
      type: String,
      default: '图标选择'
    },
    iconDialogIsShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      elementIcons
    }
  },
  methods: {
    handleClipboard(text, event) {
      this.$emit('select-icon', { text: text })
    },
    generateElementIconCode(symbol) {
      return 'el-icon-' + symbol
    }
  }
}
</script>

<style lang="scss" scoped>
.icons-container {
  margin: 10px 20px 0;
  height: 60vh;
  overflow: auto;
  .grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  .icon-item {
    display: flex;
    flex-direction: column;
    margin: 20px;
    height: 50px;
    width: 100px;
    text-align: center;
    float: left;
    font-size: 20px;
    color: #24292e;
    cursor: pointer;
  }
  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }
  .disabled {
    pointer-events: none;
  }
}
</style>
